package com.synergy.stockflow.procure.controller;

import com.synergy.stockflow.model.Result;
import com.synergy.stockflow.procure.entity.InboundDetails;
import com.synergy.stockflow.procure.service.InboundDetailsService;
import com.synergy.stockflow.sales.entity.ShippingDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/inboundDetails")
public class InboundDetailsController {
    @Autowired
    InboundDetailsService inboundDetailsService;

    @PostMapping ("/Where")
    public Result<List<InboundDetails>> getInboundDetails(@RequestBody List<InboundDetails> inboundDetails) {
        List<InboundDetails> inboundDetails1 = new ArrayList<>();
        for(InboundDetails i : inboundDetails){
            inboundDetails1.add(inboundDetailsService.selectWhere(i.getInboundDetailsPurchaseDetailsId()));
        }
        return Result.success(inboundDetails1);
    }

    @PutMapping
    public int update(@RequestBody List<InboundDetails> inboundDetails){
        for(InboundDetails i:inboundDetails){
            if(i.getInboundDetailsQuantityOfArrival().doubleValue()!=0.00 && i.getInboundDetailsQuantityOfArrival() !=null){
                inboundDetailsService.updateById(i);
            }else{
                inboundDetailsService.removeById(i.getInboundDetailsId());
            }
        }
        return 0;
    }
}
